package cn.edu.bjfu.practice.practice.student.controller;


import cn.edu.bjfu.practice.practice.app.common.response.ErrorFromUser;
import cn.edu.bjfu.practice.practice.app.common.response.Response;
import cn.edu.bjfu.practice.practice.student.pojo.query.AddTaskForm;
import cn.edu.bjfu.practice.practice.student.pojo.query.ChangeProForm;
import cn.edu.bjfu.practice.practice.student.pojo.query.ModifyTaskForm;
import cn.edu.bjfu.practice.practice.student.pojo.query.RemoveMemberForm;
import cn.edu.bjfu.practice.practice.student.service.ProjectService;
import cn.edu.bjfu.practice.practice.teacher.dao.DocumentDao;
import cn.edu.bjfu.practice.practice.teacher.service.CaseService;
import cn.edu.bjfu.practice.practice.teacher.service.TeacherService;
import org.apache.tomcat.jni.Error;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class ProjectController {

    @Autowired
    ProjectService projectService;

    @Autowired
    CaseService caseService;

    @PostMapping("/student/select_team")
    public Response<Object> selectTeam() {
        return Response.success(projectService.selectTeam());
    }

    @PostMapping("/student/join_team")
    public Response<Object> joinTeam(Integer id, Integer user_id) {
        if(projectService.joinTeam(id, user_id) == 1)
            return Response.message();
        else
            return Response.error(ErrorFromUser.JOINED_ERROR);
    }

    @PostMapping("/student/remove_member")
    public Response<Object> removeMember(RemoveMemberForm form) {
        if(projectService.removeMember(form) == 1)
            return Response.message();
        else
            return Response.error(ErrorFromUser.NO_RIGHT_ERROR);
    }

    @PostMapping("/student/add_task")
    public Response<Object> addTask(@Validated AddTaskForm form) {
        projectService.addTask(form);
            return Response.message();
    }

    @PostMapping("/student/get_my_task")
    public Response<Object> getMyTask(Integer user_id) {
        return Response.success(projectService.getMyTask(user_id));
    }

    @PostMapping("/student/select_task")
    public Response<Object> selectTask(Integer id) {
        return Response.success(projectService.selectTask(id));
    }

    @PostMapping("/student/modify_task")
    public Response<Object> modifyTask(@Validated ModifyTaskForm taskForm) {
        projectService.modifyTask(taskForm);
        return Response.message();
    }

    @PostMapping("/student/delete_task")
    public Response<Object> deleteTask(Integer id) {
        projectService.deleteTask(id);
        return Response.message();
    }

    @PostMapping("/student/select_case")
    public Response<Object> selectCase(Integer id) {
        return Response.success(caseService.getCase(id));
    }

    @PostMapping("/student/select_pro_by_pro")
    public Response<Object> selectProByPro(Integer project_id) {
        return Response.success(projectService.selectProByPro(project_id));
    }

    @PostMapping("/student/change_project")
    public Response<Object> change_project(ChangeProForm form) {
        projectService.changeProject(form);
        return Response.message();
    }

    @PostMapping("/student/get_task_detail")
    public Response<Object> getTaskDetail(Integer task_id) {
        return Response.success(projectService.getTaskDetail(task_id));
    }
}
